package com.quanshu.exchange.support.net.core;

import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.LifecycleTransformer;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.ObservableTransformer;


/**
 * 只绑定生命周期
 */
public class SampleTransformer<T> implements ObservableTransformer<T, T> {

    private LifecycleTransformer<T> transformer;//绑定Activity的生命周期

    public SampleTransformer(LifecycleProvider<?> rx) {
        this.transformer = rx.bindToLifecycle();
    }

    /**
     * 统一加上进度条、线程调度等
     */
    @Override
    public ObservableSource<T> apply(Observable<T> upstream) {

        return upstream.compose(transformer);//绑定生命周期
    }

}
